<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>消息队列故障应对方案</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .number-circle {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            font-size: 1.25rem;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .tag {
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.875rem;
            display: inline-block;
            margin-right: 8px;
            margin-bottom: 8px;
        }
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 2rem 0;
            border-radius: 0 8px 8px 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-5xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    消息队列故障应对方案
                </h1>
                <p class="text-xl mb-8 opacity-90 max-w-3xl mx-auto">
                    保障系统高可用性与业务连续性的八大策略
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="tag bg-white bg-opacity-20 text-white">
                        <i class="fas fa-shield-alt mr-2"></i>高可用架构
                    </span>
                    <span class="tag bg-white bg-opacity-20 text-white">
                        <i class="fas fa-sync-alt mr-2"></i>故障恢复
                    </span>
                    <span class="tag bg-white bg-opacity-20 text-white">
                        <i class="fas fa-database mr-2"></i>数据持久化
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="highlight-box">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="text-3xl font-serif text-purple-600 float-left mr-2 leading-none">线</span>上消息队列故障可能导致系统的消息传递中断，进而影响到业务流程的顺利进行。为了保障系统的高可用性和业务的连续性，通常需要准备一些备选方案来应对消息队列的故障。选择合适的备选方案需要综合考虑系统的架构、业务需求以及故障的影响范围。通常，在高可用性要求较高的系统中，可能会组合使用多种方案以实现更加健壮的故障处理能力。
                </p>
            </div>
        </div>
    </section>

    <!-- Architecture Diagram -->
    <section class="py-8 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-8">架构概览</h2>
            <div class="bg-white rounded-lg shadow-lg p-8">
                <div class="mermaid">
                    graph TB
                        A[应用系统] --> B{消息队列状态}
                        B -->|正常| C[消息队列]
                        B -->|故障| D[备选方案]
                        D --> E[数据库持久化]
                        D --> F[双重队列]
                        D --> G[本地缓存]
                        D --> H[重试机制]
                        D --> I[分布式日志]
                        D --> J[系统降级]
                        D --> K[事件溯源]
                        D --> L[多数据中心]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#f9f9f9,stroke:#667eea,stroke-width:2px
                        style C fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#ed8936,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- Solutions Grid -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-12">八大应对策略</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Solution 1 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <div class="flex items-start mb-4">
                        <div class="number-circle mr-4">1</div>
                        <h3 class="text-2xl font-bold text-gray-800">消息持久化到数据库</h3>
                    </div>
                    <p class="text-gray-600 mb-4">在消息队列发生故障时，可以将消息临时持久化到数据库中。应用程序在发送消息时，首先将消息保存到数据库，等消息队列恢复后，再从数据库中将消息读取并发送到队列中。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">优点：</span>
                                <span class="text-gray-600">这种方案能够确保消息不丢失，并且相对容易实现。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">缺点：</span>
                                <span class="text-gray-600">会增加数据库的负担，且恢复消息时需要额外的处理逻辑。</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Solution 2 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <div class="flex items-start mb-4">
                        <div class="number-circle mr-4">2</div>
                        <h3 class="text-2xl font-bold text-gray-800">双重消息队列</h3>
                    </div>
                    <p class="text-gray-600 mb-4">使用主备两个消息队列，在主队列出现故障时，自动切换到备用队列。可以通过配置高可用的消息队列服务（如Kafka的多节点集群）或编写切换逻辑来实现。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">优点：</span>
                                <span class="text-gray-600">高可用性强，切换过程对业务几乎透明。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">缺点：</span>
                                <span class="text-gray-600">需要管理多个队列的同步和一致性，可能增加系统复杂性。</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Solution 3 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <div class="flex items-start mb-4">
                        <div class="number-circle mr-4">3</div>
                        <h3 class="text-2xl font-bold text-gray-800">使用本地缓存</h3>
                    </div>
                    <p class="text-gray-600 mb-4">在消息队列不可用时，临时将消息缓存到本地（内存或磁盘）。待消息队列恢复后，再将缓存中的消息发送到队列中。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">优点：</span>
                                <span class="text-gray-600">实现简单，适合短时间的消息队列不可用场景。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">缺点：</span>
                                <span class="text-gray-600">缓存量有限，如果消息量大且故障时间长，可能会导致数据丢失或应用程序内存耗尽。</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Solution 4 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <div class="flex items-start mb-4">
                        <div class="number-circle mr-4">4</div>
                        <h3 class="text-2xl font-bold text-gray-800">重试机制</h3>
                    </div>
                    <p class="text-gray-600 mb-4">引入消息发送的重试机制，遇到消息队列不可用时，定期重试发送消息。可以结合指数退避算法（Exponential Backoff）来减少频繁的重试对系统的压力。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">优点：</span>
                                <span class="text-gray-600">简单易用，能有效应对短暂的网络或服务中断。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <div>
                                <span class="font-semibold text-gray-700">缺点：</span>
                                <span class="text-gray-600">无法处理长时间的消息队列不可用问题，且需要注意重试的频率和时机。</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Solution 5 -->
                <div class="bg-white rounded-lg shadow-lg p-8 card-hover">
                    <div class="flex items-start mb-4">
                        <div class="number-circle mr-4">5</div>
                        <h3 class="text-2xl font-bold text-gray-800">分布式日志系统</h3>
                    </div>
                    <p class="text-gray-600 mb-4">使用分布式日志系统（如Kafka、Pulsar）作为消息队列的备选方案，在消息队列故障时，直接写入日志系统，日志系统的消费者会在队列恢复后继续处理消息。</p>
                    <div